<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Enable throwing exceptions</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="sqlite3.createfunction.html">« SQLite3::createFunction</a></li>
      <li style="float: right;"><a href="sqlite3.escapestring.html">SQLite3::escapeString »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="class.sqlite3.html">SQLite3</a></li>
    <li>Enable throwing exceptions</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="sqlite3.enableexceptions" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">SQLite3::enableExceptions</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.3.0, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">SQLite3::enableExceptions</span> &mdash; <span class="dc-title">
   Enable throwing exceptions
  </span></p>

 </div>

 <div class="refsect1 description" id="refsect1-sqlite3.enableexceptions-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><strong>SQLite3::enableExceptions</strong></span>(<span class="methodparam"><span class="type">bool</span> <code class="parameter">$enable</code><span class="initializer"> = <strong><code>false</code></strong></span></span>): <span class="type">bool</span></div>

  <p class="para rdfs-comment">
   Controls whether the <span class="classname"><a href="class.sqlite3.html" class="classname">SQLite3</a></span> instance will
   throw exceptions or warnings on error.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-sqlite3.enableexceptions-parameters">
  <h3 class="title">参数</h3>
  <dl>
   
    <dt>
<code class="parameter">enable</code></dt>

    <dd>

     <p class="para">
      When <strong><code>true</code></strong>, the <span class="classname"><a href="class.sqlite3.html" class="classname">SQLite3</a></span> instance, and 
      <span class="classname"><a href="class.sqlite3stmt.html" class="classname">SQLite3Stmt</a></span> and <span class="classname"><a href="class.sqlite3result.html" class="classname">SQLite3Result</a></span>
      instances derived from it, will throw exceptions on error.
     </p>
     <p class="para">
      When <strong><code>false</code></strong>, the <span class="classname"><a href="class.sqlite3.html" class="classname">SQLite3</a></span> instance, and
      <span class="classname"><a href="class.sqlite3stmt.html" class="classname">SQLite3Stmt</a></span> and <span class="classname"><a href="class.sqlite3result.html" class="classname">SQLite3Result</a></span>
      instances derived from it, will raise warnings on error.
     </p>
     <p class="para">
      For either mode, the error code and message, if any, will be available via
      <span class="methodname"><a href="sqlite3.lasterrorcode.html" class="methodname">SQLite3::lastErrorCode()</a></span> and
      <span class="methodname"><a href="sqlite3.lasterrormsg.html" class="methodname">SQLite3::lastErrorMsg()</a></span> respectively.
     </p>
    </dd>

   
  </dl>

 </div>


 <div class="refsect1 returnvalues" id="refsect1-sqlite3.enableexceptions-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   Returns the old value; <strong><code>true</code></strong> if exceptions were enabled, <strong><code>false</code></strong> otherwise.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-sqlite3.enableexceptions-examples">
  <h3 class="title">范例</h3>
  <div class="example" id="sqlite3.enableexceptions.example.basic">
   <p><strong>示例 #1 <span class="methodname"><strong>SQLite3::enableExceptions()</strong></span> example</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$sqlite&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">SQLite3</span><span style="color: #007700">(</span><span style="color: #DD0000">':memory:'</span><span style="color: #007700">);<br />try&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$sqlite</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">exec</span><span style="color: #007700">(</span><span style="color: #DD0000">'create&nbsp;table&nbsp;foo'</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$sqlite</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">enableExceptions</span><span style="color: #007700">(</span><span style="color: #0000BB">true</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$sqlite</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">exec</span><span style="color: #007700">(</span><span style="color: #DD0000">'create&nbsp;table&nbsp;bar'</span><span style="color: #007700">);<br />}&nbsp;catch&nbsp;(</span><span style="color: #0000BB">Exception&nbsp;$e</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">'Caught&nbsp;exception:&nbsp;'&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">$e</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getMessage</span><span style="color: #007700">();<br />}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

   <div class="example-contents"><p>以上例程的输出类似于：</p></div>
   <div class="example-contents screen">
<div class="cdata"><pre>
Warning: SQLite3::exec(): near &quot;foo&quot;: syntax error in example.php on line 4
Caught exception: near &quot;bar&quot;: syntax error
</pre></div>
   </div>
  </div>
 </div>


</div></div></div></body></html>